//
//  MTPartyGiftSelectCell.swift
//  MT
//
//  Created by ooops on 2020/5/25.
//  Copyright © 2020 张强. All rights reserved.
//

import UIKit
import MTCategory
import Kingfisher

class MTPartyGiftSelectCell: UICollectionViewCell {
    class func reuseIdentity() -> String {
        return "MTPartyGiftSelectCellID"
    }
    
    func bindData(data: PartyGiftItemStruct, isHiddenContent: Bool = false) {
        if !isHiddenContent {
            //iconImageView.mtSetImage(data.icon, nil)
            //arrtibute(text: "\(data.count)", icon: data.icon, position: 0)
            countLabel.text = "x \(data.count)"
            customCountLabel.isHidden = !isHiddenContent
            countLabel.isHidden = isHiddenContent
            iconImageView.isHidden = isHiddenContent
        } else {
            customCountLabel.text = "自定义数量"
            customCountLabel.isHidden = !isHiddenContent
            countLabel.isHidden = isHiddenContent
            iconImageView.isHidden = isHiddenContent
        }
        if data.isSelected == true {
            //self.gLayer.removeFromSuperlayer()
            contentView.layer.borderColor = UIColor(hex: 0xffc000).cgColor
            contentView.layer.borderWidth = 3
            moneySelectedView.isHidden = false
        } else {
            contentView.layer.borderColor = UIColor.text.x9b9b9b.cgColor
            contentView.layer.borderWidth = 1
            moneySelectedView.isHidden = true
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        makeConstraint()
        
        contentView.layer.borderColor = UIColor(hex: 0xffc000).cgColor
        contentView.layer.borderWidth = 2
        contentView.layer.cornerRadius = 4
    }
    
    lazy var moneySelectedView: UIImageView = {
        let imageV = UIImageView(image: UIImage(named: "money-selected"))
        imageV.sizeToFit()
        imageV.isHidden = true
        return imageV
    }()
    
    lazy var iconImageView: UIImageView = {
        let imageV = UIImageView()
//        imageV.backgroundColor = .red
        imageV.image = UIImage(named: "club_gift")
        return imageV
    }()
    
    lazy var countLabel: UILabel = {
        let l = UILabel()
        l.font = PingFangSCMediumFont(20)
        l.textColor = UIColor.text.x1d1a1a
        l.text = "x1000"
        l.adjustsFontSizeToFitWidth = true
        return l
    }()
    
    lazy var customCountLabel: UILabel = {
        let l = UILabel()
        l.font = PingFangSCMediumFont(14)
        l.textColor = UIColor.text.x1d1a1a
        l.text = "自定义数量"
        l.textAlignment = .center
        return l
    }()
    
    private func setupUI() {
        contentView.addSubview(countLabel)
        contentView.addSubview(iconImageView)
        contentView.addSubview(customCountLabel)
        contentView.addSubview(moneySelectedView)
    }
    
    private func makeConstraint() {
        countLabel.snp.makeConstraints { (make) in
            make.left.equalTo(iconImageView.snp.right).offset(5)
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-10)
        }
        
        customCountLabel.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
        iconImageView.snp.makeConstraints { (make) in
            make.right.equalTo(self.snp.centerX).offset(-15)
            make.centerY.equalToSuperview()
            make.height.width.equalTo(24)
        }
        
        moneySelectedView.snp.makeConstraints { (make) in
            make.right.bottom.equalToSuperview()
        }
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
}
